<style lang="less">
@import "@/styles/table-common.less";
.btn-box {
  // padding: 10px 12px 10px 0;
  height: 32px;
  display: flex;
  align-items: center;
  span {
    margin-left: 15px;
  }
}
.detail-modal {
  .form {
    div {
      display: flex;
      margin-bottom: 10px;
      span {
        width: 130px;
      }
      input {
        flex: 1;
        border: 1px solid #e8eaec;
        outline: none;
        text-indent: 16px;
        color: #515a6e;
      }
    }
  }
  .refund-num {
    margin-top: 15px;
  }
}
</style> 
<template>
  <div class="search">
    <Card>
      <Form ref="searchForm" :model="searchForm" inline :label-width="100">
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
          <FormItem label="时间">
            <DatePicker
              :options="options"
              v-model="selectDate"
              type="daterange"
              format="yyyy-MM-dd"
              clearable
              @on-change="selectDateRange"
              placeholder="选择起始时间"
              style="width: 200px"
            ></DatePicker>
          </FormItem>
          <FormItem :label="title0">
            <Select
              v-model="searchForm.productId"
              transfer
              placeholder="请选择"
              style="width: 200px"
            >
              <Option
                v-for="item in foodCompanys"
                :key="item.id"
                :value="item.id"
                >{{ item.title }}</Option
              >
            </Select>
          </FormItem>
          <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
          </FormItem>
        </Row>
      </Form>

      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
        <!-- <template slot-scope="{ row }" slot="print">{{ row.print.serialNo }}</template> -->
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
  </div>
</template>

<script>
import {
  getscOrderActiveByCondition,
  getScParkRoleMemberRole,
  getAllByTypeData,
} from "@/api/index";
import { shortcuts } from "@/libs/shortcuts";

export default {
  name: "user-manage",
props:['orderType','chipdata'],
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      
      message: "",
      showUser: false,
      loading: true,
      selectDate: "",
      openSearch: true,
      options: {
        shortcuts: shortcuts,
      },
      foodCompanys: [],
      searchForm: {
        pageNumber: 1,
        pageSize: "10",
        // sort: "createTime",
        // order: "desc",
      },
      columns: [
        {
          title: "姓名",
          key: "name",
        
          align: "center",
        },
        {
          title: "昵称",
          key: "nickname",
         
          align: "center",
        },
        {
          title: "手机号",
          key: "mobile",
         
          align: "center",
        },
        {
          title: "身份证号",
          key: "idCard",
        
          align: "center",
        },
        {
          title: "参与时间",
          key: "createTime",
        
          align: "center",
        }
      ],
    };
  },
  methods: {
    init() {
      if (this.orderType == 7) {
          this.title0='会员类型'
        getScParkRoleMemberRole().then((res) => {
          if (res.success) {
            this.foodCompanys = res.result;
          }
        });
      } else if (this.orderType == 5) {
           this.title0='活动名称'
        getAllByTypeData("scActivity").then((res) => {
          if (res.success) {
            this.foodCompanys = res.result;
          }
        });
      }

      this.searchForm.orderType = this.orderType;
      this.searchForm.productId = this.chipdata.productId;
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      // 多条件搜索用户列表
      this.loading = true;
      if (this.userInfo.type != 1) {
        this.searchForm.companyId = this.userInfo.companyId;
      }
      getscOrderActiveByCondition(this.searchForm).then((res) => {
        this.loading = false;
        console.log(res.message);
        if (res.success) {
          this.data = res.result.records;
          this.total = res.result.total;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      });
    },

    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      console.log(this.searchForm);
      // return
      this.getDataList();
    },
    handleReset() {
      this.selectDate = "";

      // 重新加载数据
      this.searchForm = {
        orderType: this.orderType,
        pageNumber: 1,
        pageSize: 10,
      };
      this.getDataList();
    },
  },
  created() {},
  mounted() {
    // 计算高度

    this.init();
  },
};
</script>